package com.ruoyi.hospital.controller.hospital;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.hospital.domain.hospital.HisDepartment;
import com.ruoyi.hospital.service.hospital.IHisDepartmentService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 医院科室Controller
 * 
 * @author ruoyi
 * @date 2024-08-13
 */
@RestController
@RequestMapping("/hospital/department")
public class HisDepartmentController extends BaseController
{
    @Autowired
    private IHisDepartmentService hisDepartmentService;

    /**
     * 查询医院科室列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:department:list')")
    @GetMapping("/list")
    public AjaxResult list(HisDepartment hisDepartment)
    {
        List<HisDepartment> list = hisDepartmentService.selectHisDepartmentList(hisDepartment);
        return success(list);
    }

    /**
     * 导出医院科室列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:department:export')")
    @Log(title = "导出医院科室", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HisDepartment hisDepartment)
    {
        List<HisDepartment> list = hisDepartmentService.selectHisDepartmentList(hisDepartment);
        ExcelUtil<HisDepartment> util = new ExcelUtil<HisDepartment>(HisDepartment.class);
        util.exportExcel(response, list, "医院科室数据");
    }

    /**
     * 获取医院科室详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:department:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(hisDepartmentService.selectHisDepartmentById(id));
    }

    /**
     * 新增医院科室
     */
    @PreAuthorize("@ss.hasPermi('hospital:department:add')")
    @Log(title = "新增医院科室", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HisDepartment hisDepartment)
    {
        return toAjax(hisDepartmentService.insertHisDepartment(hisDepartment));
    }

    /**
     * 修改医院科室
     */
    @PreAuthorize("@ss.hasPermi('hospital:department:edit')")
    @Log(title = "修改医院科室", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HisDepartment hisDepartment)
    {
        return toAjax(hisDepartmentService.updateHisDepartment(hisDepartment));
    }

    /**
     * 删除医院科室
     */
    @PreAuthorize("@ss.hasPermi('hospital:department:remove')")
    @Log(title = "删除医院科室", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(hisDepartmentService.deleteHisDepartmentByIds(ids));
    }
}
